package com.qiqi.service.phonenumber.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qiqi.dao.PhoneNumberMapper;
import com.qiqi.domain.PhoneNumber;
import com.qiqi.domain.PhoneNumberExample;
import com.qiqi.service.phonenumber.PhoneNumberService;
/**
 * 号码查询服务
 * @author Administrator
 *
 */
@Service("phoneNumberService")
public class PhoneNumberServiceImpl implements PhoneNumberService{
	@Autowired
	private PhoneNumberMapper phoneNumberMapper;
	public Map<String, Object> findNumbersByPage(PhoneNumberExample query,
			int page, int pageSize) {
		page=page==0?1:page;
		pageSize=pageSize==0?20:pageSize;
		Map<String, Object> res=new HashMap<String, Object>();
		query.setLimitStart((page-1)*pageSize);
		query.setLimitEnd(pageSize);
		int count = phoneNumberMapper.countByExample(query);
		List<PhoneNumber> list = phoneNumberMapper.selectByExample(query);
		res.put("list", list);
		res.put("total", count);
		return res;
	}
	public Integer addNumber(PhoneNumber number) {
		if(number!=null&&StringUtils.isNotBlank(number.getNum())){
			PhoneNumberExample query = new PhoneNumberExample();
			query.createCriteria().andNumEqualTo(number.getNum());
			int count = phoneNumberMapper.countByExample(query);
			if(count>0){
				return 0;
			}else{
				int state = phoneNumberMapper.insertSelective(number);
				return state;
			}
		}
		return -1;
	}

}
